using System.Collections.Generic;
using Kimgwajang.MidnightPeach.Schema;

namespace Kimgwajang.MidnightPeach.Generators
{
    internal class TableGenerator : Generator
    {
        private readonly Table _table;

        public TableGenerator(SortedDictionary<string, string> variables, Table table) : base(variables)
        {
            _table = table;
        }

        internal override string Generate(Macro macro, string text)
        {
            switch (macro.Value)
            {
                case "PascalName":
                    return _table.PascalName;

                case "CamelName":
                    return _table.CamelName;

                case "DbName":
                    return _table.DbName;

                case "Schema":
                    return _table.Schema;

                case "BeginCommentIfView":
                    return _table.TableType == TableType.Table ? string.Empty : "/* not available for view";

                case "EndCommentIfView":
                    return _table.TableType == TableType.Table ? string.Empty : "*/";

                case "CommaIfHasInc":
                    return _table.HasIncrementalColumn() ? "," : string.Empty;

                case "FirstColumnDbName":
                    return _table.Columns[0].DbName;

                case "BeginCommentIfMapping":
                    return _table.IsMappingTable() ? "/* not available for mapping table that has only two columns." : string.Empty;

                case "EndCommentIfMapping":
                    return _table.IsMappingTable() ? "not available for mapping table that has only two columns. */" : string.Empty;

                default:
                    throw new UnsupportedMacroException(macro, text, this);
            }
        }
    }
}